package com.ms.mapper;

import com.ms.pojo.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserManageMapper {

    /**
     * 分页查询所有员工
     */
    @Select("SELECT * FROM employee LIMIT #{offset}, #{limit}")
    List<Employee> selectAllWithPagination(@Param("offset") int offset, @Param("limit") int limit);
    /**
     * 查询员工总数
     */
    @Select("SELECT COUNT(*) FROM employee")
    long countAll();

    /**
     * 根据ID查询员工
     */
    @Select("SELECT * FROM employee WHERE emp_id = #{empId}")
    Employee selectById(Integer empId);

    /**
     * 添加员工
     */
    @Insert("INSERT INTO employee(login_id, emp_name, gender, dept_id, position, phone, email, hire_date, address, update_time) " +
            "VALUES(#{loginId}, #{empName}, #{gender}, #{deptId}, #{position}, #{phone}, #{email}, #{hireDate}, #{address}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "empId")
    int insert(Employee employee);

    /**
     * 更新员工信息
     */
    @Update("UPDATE employee SET  emp_name=#{empName}, gender=#{gender}, dept_id=#{deptId}, " +
            "position=#{position}, phone=#{phone}, email=#{email}, hire_date=#{hireDate}, resign_date=#{resignDate}, " +
            "address=#{address}, update_time=#{updateTime} WHERE emp_id=#{empId}")
    int update(Employee employee);

    /**
     * 删除员工
     */
    @Delete("DELETE FROM employee WHERE emp_id = #{empId}")
    int deleteById(Integer empId);

}
